package org.scmpatrol.scm.action;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.scmpatrol.scm.SCMEntry;
import org.scmpatrol.scm.SCMPath;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "action")
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "type", discriminatorType = DiscriminatorType.CHAR)
@DiscriminatorValue(value = "0")
public abstract class SCMAction implements Serializable {

    private static final long serialVersionUID = -2999601907357246576L;

    /**
     * the internal id
     */
    @Id
    @GeneratedValue
    Long id;

    SCMPath path;

    @ManyToOne
    SCMEntry scmElement;
                          
    /**
     * Default constructor for persistance
     */
    protected SCMAction() {
    }

    protected SCMAction(SCMPath path) {
        this.path = path;
    }

    public abstract SCMActionTypeEnum getActionType();

    public SCMPath getPath() {
        return path;
    }

    public void setPath(SCMPath path) {
        this.path = path;
    }

    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

}
